<%@ include file="/common/taglibs.jsp" %>

<head>
    <title><fmt:message key="loanProductDetail.title"/></title>
    <meta name="menu" content="LoanRequestListMenu"/>
    <meta name="heading" content="<fmt:message key='loanProductDetail.heading'/>"/>
</head>

<c:set var="delObject" scope="request"><fmt:message key="loanProductList.loanProduct"/></c:set>
<script type="text/javascript">var msgDelConfirm =
        "<fmt:message key="delete.confirm"><fmt:param value="${delObject}"/></fmt:message>";
</script>
<!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        <fmt:message key="loanProductDetail.heading"/>
    </h1>
    <fmt:message key="loanProductDetail.message"/>
    <ol class="breadcrumb">
        <li><a href="/loanRequests"><i class="fa fa-dashboard"></i><fmt:message key="loanProductList.heading"/></a></li>
        <li class="active"><fmt:message key="loanProductDetail.heading"/></li>
    </ol>
</section>
<!-- Main content -->
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-primary">
                <div class="box-body">
                    <%@ include file="/common/messages.jsp" %>
                        <form:errors path="*" cssClass="alert alert-danger alert-dismissable" element="div"/>
                        <form:form commandName="loanProduct" method="post" action="loanProductform" cssClass="form-horizontal margin"
                                   id="loanProductForm" onsubmit="return validateLoanProduct(this)">
                            <form:hidden path="id"/>
                            <form:hidden path="bank.id"/>
                            <spring:bind path="loanProduct.productName">
                                <input type="hidden" name="from" value="<c:out value="${param.from}"/>"/>

                                <div class="form-group${(not empty status.errorMessage) ? ' has-error' : ''}">
                            </spring:bind>
                            <appfuse:label key="loanProduct.productName" styleClass="control-label col-sm-1"/>
                            <div class="col-sm-3">
                            <form:input cssClass="form-control" path="productName" id="productName" maxlength="255"/>
                            <form:errors path="productName" cssClass="help-block"/></div>
                            </div>
                            <spring:bind path="loanProduct.enabled">
                                <div class="form-group${(not empty status.errorMessage) ? ' has-error' : ''}">
                            </spring:bind>
                            <appfuse:label key="loanProduct.enabled" styleClass="control-label col-sm-1"/>
                            <div class="col-sm-3">
                                <div class="input-group">
                                    <form:checkbox path="enabled" id="enabled"/></div>
                                <form:errors path="enabled" cssClass="help-block"/></div>
                            </div>
                            <spring:bind path="loanProduct.bank">
                                <div class="form-group${(not empty status.errorMessage) ? ' has-error' : ''}">
                            </spring:bind>
                            <appfuse:label key="loanProduct.bank" styleClass="control-label col-sm-1"/>
                            <div class="col-sm-3">
                            <form:input cssClass="form-control" path="bank.name" id="bank" maxlength="255" readonly="true"/>
                            <form:errors path="bank.name" cssClass="help-block"/></div>
                            </div>
                            <spring:bind path="loanProduct.second">
                                <div class="form-group${(not empty status.errorMessage) ? ' has-error' : ''}">
                            </spring:bind>
                            <appfuse:label key="loanProduct.second" styleClass="control-label col-sm-1"/>
                            <div class="col-sm-3">
                                <div class="input-group">
                                    <form:checkbox path="second" id="second"/></div>
                                <form:errors path="second" cssClass="help-block"/></div>
                            </div>
                            <spring:bind path="loanProduct.costRate">
                                <div class="form-group${(not empty status.errorMessage) ? ' has-error' : ''}">
                            </spring:bind>
                            <appfuse:label key="loanProduct.costRate" styleClass="control-label col-sm-1"/>
                            <div class="col-sm-3">
                                <div class="input-group">
                                    <form:input cssClass="form-control" path="costRate" id="coef" maxlength="255"/><div class="input-group-addon">%</div></div>
                                <form:errors path="costRate" cssClass="help-block"/></div>
                            </div>
                            <spring:bind path="loanProduct.coef">
                                <div class="form-group${(not empty status.errorMessage) ? ' has-error' : ''}">
                            </spring:bind>
                            <appfuse:label key="loanProduct.coef" styleClass="control-label col-sm-1"/>
                            <div class="col-sm-3">
                                <div class="input-group">
                            <form:input cssClass="form-control" path="coef" id="coef" maxlength="255"/><div class="input-group-addon">%</div></div>
                            <form:errors path="coef" cssClass="help-block"/></div>
                            </div>
                            <spring:bind path="loanProduct.crLL">
                                <div class="form-group${(not empty status.errorMessage) ? ' has-error' : ''}">
                            </spring:bind>
                            <appfuse:label key="loanProduct.crLL" styleClass="control-label col-sm-1"/>
                                <div class="col-sm-3">
                                    <div class="input-group">
                            <form:input cssClass="form-control" path="crLL" id="crLL" maxlength="255"/><div class="input-group-addon">%</div></div>
                            <form:errors path="crLL" cssClass="help-block"/></div>
                            </div>
                            <spring:bind path="loanProduct.crUL">
                                <div class="form-group${(not empty status.errorMessage) ? ' has-error' : ''}">
                            </spring:bind>
                            <appfuse:label key="loanProduct.crUL" styleClass="control-label col-sm-1"/>
                                <div class="col-sm-3">
                                    <div class="input-group">
                            <form:input cssClass="form-control" path="crUL" id="crUL" maxlength="255"/><div class="input-group-addon">%</div></div>
                            <form:errors path="crUL" cssClass="help-block"/></div>
                            </div>
                            <spring:bind path="loanProduct.dpLL">
                                <div class="form-group${(not empty status.errorMessage) ? ' has-error' : ''}">
                            </spring:bind>
                            <appfuse:label key="loanProduct.dpLL" styleClass="control-label col-sm-1"/>
                                <div class="col-sm-3">
                                    <div class="input-group">
                            <form:input cssClass="form-control" path="dpLL" id="dpLL" maxlength="255"/><div class="input-group-addon">%</div></div>
                            <form:errors path="dpLL" cssClass="help-block"/></div>
                            </div>
                            <spring:bind path="loanProduct.dpUL">
                                <div class="form-group${(not empty status.errorMessage) ? ' has-error' : ''}">
                            </spring:bind>
                            <appfuse:label key="loanProduct.dpUL" styleClass="control-label col-sm-1"/>
                                <div class="col-sm-3">
                                    <div class="input-group">
                            <form:input cssClass="form-control" path="dpUL" id="dpUL" maxlength="255"/><div class="input-group-addon">%</div></div>
                            <form:errors path="dpUL" cssClass="help-block"/></div>
                            </div>
                            <spring:bind path="loanProduct.faLL">
                                <div class="form-group${(not empty status.errorMessage) ? ' has-error' : ''}">
                            </spring:bind>
                            <appfuse:label key="loanProduct.faLL" styleClass="control-label col-sm-1"/>
                                <div class="col-sm-3">
                            <form:input cssClass="form-control" path="faLL" id="faLL" maxlength="255"/>
                            <form:errors path="faLL" cssClass="help-block"/></div>
                            </div>
                            <spring:bind path="loanProduct.faUL">
                                <div class="form-group${(not empty status.errorMessage) ? ' has-error' : ''}">
                            </spring:bind>
                            <appfuse:label key="loanProduct.faUL" styleClass="control-label col-sm-1"/>
                                <div class="col-sm-3">
                            <form:input cssClass="form-control" path="faUL" id="faUL" maxlength="255"/>
                            <form:errors path="faUL" cssClass="help-block"/></div>
                            </div>
                            <spring:bind path="loanProduct.loanYears">
                                <div class="form-group${(not empty status.errorMessage) ? ' has-error' : ''}">
                            </spring:bind>
                            <appfuse:label key="loanProduct.loanYears" styleClass="control-label col-sm-1"/>
                                <div class="col-sm-3">
                                    <form:checkbox path="loanYears" cssClass="insure" value="1"/><fmt:message key="LOAN_YEARS_1"/>
                                    <form:checkbox path="loanYears" cssClass="insure" value="2" /><fmt:message key="LOAN_YEARS_2"/>
                                    <form:checkbox path="loanYears" cssClass="insure" value="3" /><fmt:message key="LOAN_YEARS_3"/>
                                    <form:checkbox path="loanYears" cssClass="insure" value="4" /><fmt:message key="LOAN_YEARS_4"/>
                                    <form:checkbox path="loanYears" cssClass="insure" value="5" /><fmt:message key="LOAN_YEARS_5"/>
                            <form:errors path="loanYears" cssClass="help-block"/></div>
                            </div>
                            <spring:bind path="loanProduct.bondIds">
                            <div class="form-group${(not empty status.errorMessage) ? ' has-error' : ''}">
                            </spring:bind>
                                <label class="control-label col-sm-1"><fmt:message key="loanProduct.chooseBond"/></label>
                                <div class="col-sm-3">
                                    <form:hidden path="bondIds" id="bondIdValues"/>
                                        <%--<form:select cssClass="form-control" path="bondIds" id="bondIds" multiple="multiple">--%>
                                        <%--<form:options items="${availableBondCompany}" itemValue="value" itemLabel="label"/>--%>
                                        <%--</form:select>--%>
                                            <div id="bondIds"></div>
                                        <form:errors path="bondIds" cssClass="help-block"/>
                                </div>
                            </div>

                            <spring:bind path="loanProduct.completeLoanMaterialNames">
                                <div class="form-group${(not empty status.errorMessage) ? ' has-error' : ''}">
                            </spring:bind>
                            <label class="control-label col-sm-1"><fmt:message key="loanProduct.chooseCompleteLoanMaterialName"/></label>
                            <div class="col-sm-3">
                                <form:select cssClass="form-control" path="completeLoanMaterialNames" id="completeLoanMaterialNames" multiple="multiple">
                                    <form:options items="${availableMaterialNames}" itemValue="value" itemLabel="label"/>
                                </form:select>
                                <form:errors path="completeLoanMaterialNames" cssClass="help-block"/>
                            </div>
                            </div>

                            <spring:bind path="loanProduct.loanMaterialNames">
                                <div class="form-group${(not empty status.errorMessage) ? ' has-error' : ''}">
                            </spring:bind>
                            <label class="control-label col-sm-1"><fmt:message key="loanProduct.chooseLoanMaterialName"/></label>
                            <div class="col-sm-3">
                                <form:select cssClass="form-control" path="loanMaterialNames" id="loanMaterialNames" multiple="multiple">
                                <form:options items="${availableMaterialNames}" itemValue="value" itemLabel="label"/>
                                </form:select>
                                <form:errors path="loanMaterialNames" cssClass="help-block"/>
                            </div>
                            </div>


                            <div class="form-group">
                                <div class="col-sm-offset-1 col-sm-11">
                                <button type="submit" class="btn btn-primary" id="save" name="save"
                                        onclick="bCancel=false">
                                    <i class="icon-ok icon-white"></i> <fmt:message key="button.save"/>
                                </button>
                                <c:if test="${not empty loanProduct.id}">
                                    <button type="submit" class="btn btn-danger" id="delete" name="delete"
                                            onclick="bCancel=true;return confirmMessage(msgDelConfirm)">
                                        <i class="icon-trash icon-white"></i> <fmt:message key="button.delete"/>
                                    </button>
                                </c:if>

                                <button type="submit" class="btn btn-default" id="cancel" name="cancel"
                                        onclick="bCancel=true">
                                    <i class="icon-remove"></i> <fmt:message key="button.cancel"/>
                                </button>
                                    </div>
                            </div>
                        </form:form>
                </div>
            </div>
        </div>
    </div>
</section>
<c:set var="scripts" scope="request">
<v:javascript formName="loanProduct" cdata="false" dynamicJavascript="true" staticJavascript="false"/>
<script type="text/javascript" src="<c:url value='/scripts/validator.jsp'/>"></script>

<script type="text/javascript">
    $(document).ready(function () {
        function toJstree(list){
            var jsTreeList = [];
            list.forEach(function(i){
                jsTreeList.push({'id':i['id'],'text': i['name'], 'children':toJstree(i['children']), "state" : { "selected" : $.inArray(i['id'].toString(),document.bondIds)>-1 }});
            })
            return jsTreeList;
        }
        $("input[type='text']:visible:enabled:first", document.forms['loanProductForm']).focus();

        $('#loanMaterialNames').multiSelect();
        $('#completeLoanMaterialNames').multiSelect();

        if($("#bondIdValues").val()!=null){
            document.bondIds = $("#bondIdValues").val().split(',');
            $.ajax('/bondCompanyform/all/children').done(function(data){
                if(data.length>0){
                    $('#bondIds').jstree({
                        "core" : {
                            "animation" : 0,
                            "check_callback" : true,
                            "themes" : { "stripes" : true },
                            'data' : toJstree(data)
                        },
                        "plugins" : [
                            "wholerow", "checkbox"
                        ]
                    });

                }

            })
        }

        $("#save").click(function(){
            //alert();
            $("#bondIdValues").val($('#bondIds').jstree("get_selected"));
        })


    });
</script>
</c:set>